home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Alpha ƒ / Tcl / SystemCode / smarterSource.tcl < prev    next >
Text File  |  1996-01-19  |  6KB  |  148 lines

  1. ####################################################################
  2. #  EvoX - evolution in complex systems
  3. #  FILE: "smarterSource.tcl"
  4. #                                    created: 4/7/95 {1:44:01 pm} 
  5. #                                last update: 4/7/95 {1:46:55 pm} 
  6. #  Author: Vince Darley
  7. #  E-mail: <mailto:vince@das.harvard.edu>
  8. #    mail: Division of Applied Sciences, Harvard University
  9. #          Oxford Street, Cambridge MA 02138, USA
  10. #  <http://www.das.harvard.edu/users/students/Vincent_Darley/>
  11. #  
  12. ####################################################################
  13.  
  14. ## 
  15.  # This    file is    part of    the    package    "Vince's Additions".
  16.  # See its documentation for more details. 
  17.  # 
  18.  # Bug reports and feature requests - please email me.
  19.  ##
  20.  
  21. #############################################################################
  22. # BASED UPON 'smartSource.tcl':
  23. #
  24. # Copyright 1994, Robert Browning (osiris@cs.utexas.edu): This code is made 
  25. # freely available to anyone who can find a use for it. Consider it part of my
  26. # thanks to all those who have contributed to the freeware and shareware base.
  27. # (Especially Pete Keheler, without which this code would be pretty useless).
  28. # === Modifications by Vince, May 1995 ===
  29. #############################################################################
  30. # This file implements a replacement source command. It is intended to help
  31. # make the process of augmenting Alpha's code base with your own changes less
  32. # awkward, especially in the face of program updates. It also makes it so
  33. # that you no longer have to source files containing procedures that you want
  34. # to override in your UserStartup file.
  35. # Basically, you designate a directory (right now it has to be a directory
  36. # named TclExtensions in the $HOME directory) to contain your files. Then
  37. # anytime Alpha is instructed to source a file named filename.tcl, it will
  38. # first look in the directory you have designated, and if there is a file of
  39. # the identical name there (i.e. filename.extension) it will source that file
  40. # instead of the original one specified. If there are any files named
  41. # filename+*.extension it will source those in the order returned by glob after
  42. # either the original filename.extension or the replacement has been sourced.
  43. # For example, if your TclExtensions directory contains files named
  44. # latex+1.tcl and latex+2.tcl, then whenever you try to open a latex file
  45. # Alpha will first source the standard latex.tcl file, then latex+1.tcl, then
  46. # latex+2.tcl. If there was also a file named latex.tcl in the TclExtensions
  47. # directory then that file would be sourced in place of the standard
  48. # latex.tcl, then latex+1.tcl, then latex+2.tcl.
  49. # You may just want to use filename+.extension for a single extension file.
  50. # Note that latex+10.tcl would be sourced _before_ latex+9.tcl, so you
  51. # may wish to use latex+01.tcl ... latex+99.tcl to make things clearer.
  52. #
  53. #############################################################################
  54. #     Fixes:
  55. #    10/10/94: Fixed it to handle non .tcl file extensions.
  56. #   01/05/95: Resent to Pete due to earlier transmission error that replaced
  57. #             + characters with * characters.
  58. #
  59. #############################################################################
  60. # To Do:
  61. #
  62. #     What do you want?
  63.  
  64. ## 
  65.  # VMD May'95: <mailto:vince@das.harvard.edu>
  66.  # 
  67.  # Changed default directory to    the    the    alpha preferences directory.
  68.  # Changed extension to    '+'    rather than    'bullet' (option-8)    because
  69.  # of ascii    transmission problems -    lots of    people have    a non-working
  70.  # version of this file.
  71.  # 
  72.  # Passes through 'tclIndex' and 'prefs.tcl' unchanged.
  73.  # 
  74.  # Renamed this    file to    'smarterSource.tcl', originally    just to    differentiate
  75.  # it from the old crippled    versions.
  76.  # 
  77.  # IMPORTANT: Fixed    the    script so that it works    with path names    containing
  78.  # spaces.
  79.  # 
  80.  # Now implements part of a    new    mode-specific preferences mechanism. Every
  81.  # Alpha mode should have a    'dummy${mode}' proc, which is called to    ensure
  82.  # a particular    mode's tcl files have been sourced.    If such    a file is
  83.  # sourced,    smarterSource will subsequently    source a file '${mode}Prefs.tcl'
  84.  # in the preferences directory, if    it exists.
  85.  # 
  86.  # See "modePrefs.tcl",    for    the    other bits of the implementation.
  87.  ##
  88.  
  89. set tclExtensionsDir "$PREFS"
  90.  
  91. if {[file exists "${tclExtensionsDir}"]} {
  92.     if {![string length [info commands oldSource]]} {
  93.         rename source oldSource
  94.     }
  95.     proc source {filename} {
  96.         global tclExtensionsDir modes modeFiles PREFS
  97.         set justName [file tail "$filename"]
  98.         set overrideFile "${tclExtensionsDir}:${justName}"
  99.         
  100.         # changed '#0' to '1'
  101.         if { $justName == "tclIndex" } { return [uplevel 1 oldSource \{$filename\} ] }
  102.         if { $justName == "prefs.tcl" } { return [uplevel #0 oldSource \{$filename\} ] }
  103.  
  104.         if {[file exists $overrideFile]} {
  105.             set returnVal [uplevel #0 oldSource \{$overrideFile\} ]
  106.         } else {
  107.             set returnVal [uplevel #0 oldSource \{$filename\} ]
  108.         }
  109.         
  110.         set baseName [string range ${justName} 0 \
  111.             [expr   [string length ${justName}] - \
  112.                     [string length [file extension ${justName}]] - 1]]
  113.         
  114.         ## 
  115.          # Mode    specific preferences stuff
  116.          ##
  117.         if [array exists modeFiles] {
  118.             if { [lsearch [array names modeFiles] $justName] != -1 } {
  119.                 foreach m $modeFiles($justName) {
  120.                     set f "${PREFS}:${m}Prefs.tcl"
  121.                     if [file exists "$f" ] {
  122.                         set returnVal [uplevel #0 oldSource \{$f\} ]
  123.                     }
  124.                 }
  125.             }
  126.         }
  127.         
  128.         set extensionFiles \
  129.             [glob -nocomplain \
  130.                 "${tclExtensionsDir}:${baseName}+*[file extension ${justName}]"]
  131.     
  132.         foreach extensionFile $extensionFiles {
  133.             set returnVal [uplevel #0 oldSource \{$extensionFile\} ]
  134.         }
  135.         return "$returnVal" 
  136.     }
  137. }
  138.  
  139.